import React, { Component } from 'react';
import {detail} from '../api/detail';
import {addCar} from '../api/car';
import IsLogin from '../../utils/isLogin';

class Detail extends Component {

    state = {
        detail:{}
    }

    componentDidMount(){
        //获取id
        console.log(this.props.match.params.id)

        detail(this.props.match.params.id).then(res => {
            console.log(res);
            this.setState({
                detail:res.data.data
            })
        })
    }
    render() {
        let {detail} = this.state;
        return (
            <div>
                {detail.title}

                <button onClick={() => this.add(detail.id)}>添加购物车</button>
            </div>
        );
    }

    add = (id) => {
        addCar({product_id:id+''}).then(res => {
            console.log(res);
        })
    }
}

export default IsLogin(Detail);